package demo4;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 何华树
 * Date: 2024-09-06
 * Time: 9:47
 */
public class Person implements Comparable<Person>{
    public String name;
    public int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Person person) {
        Person tmp = person;
        //根据年龄进行比较
        //return this.age - tmp.age;

        //根据名字进行比较
        return this.name.compareTo(tmp.name);
    }
}
